const shop = require('../../../mixins/shop')
const common = require('../../../mixins/common')
const app = getApp()

const options = {
  /**
   * 页面的初始数据
   */
  data: {
    focusShow: false,
    keyword: "",
    cats: [{
      id: -1,
      name: "上新"
    }, {
      id: 0,
      name: "热销榜单"
    }],
    curIdx: -1,
    goodsList: [],
    page: 1,
    loading: true,
    loadmoreShow: false,
    isLastPage: false,
    isEmpty: false,
  },

  onLoad: function (options) {
    let that = this;
    that.setData({
      focusShow: Number(options.focusShow),
      curIdx: options.id,
    })
    that.getShopClassify();
    that.getShopClassifyGoodsList();
  },

  delKeyword() {
    let that = this;
    that.setData({
      keyword: '',
      loading: true,
      loadmoreShow: false,
      isLastPage: false,
      isEmpty: false,
      page: 1,
      goodsList: [],
    });
    that.getShopClassifyGoodsList();
  },

  onSearchConfirm(e) {
    let that = this;
    that.setData({
      keyword: e.detail.value,
      loading: true,
      loadmoreShow: false,
      isLastPage: false,
      isEmpty: false,
      page: 1,
      goodsList: [],
    })
    that.getShopGoodsSearch();
  },

  switchRightTab: function (e) {
    let that = this;
    that.setData({
      curIdx: e.target.dataset.id,
      loading: true,
      loadmoreShow: false,
      isLastPage: false,
      isEmpty: false,
      page: 1,
      goodsList: [],
    });
    that.getShopClassifyGoodsList();
  },

  toGoodsDetail(e) {
    wx.navigateTo({
      url: '/pages/shop/goods-details/goods-details?id=' + e.currentTarget.dataset.id,
    })
  },

  onPullDownRefresh: function () {
    let that = this;
    that.setData({
      loading: true,
      loadmoreShow: false,
      isLastPage: false,
      isEmpty: false,
      page: 1,
      goodsList: [],
    });
    that.getShopClassifyGoodsList();
    wx.stopPullDownRefresh();
  },

  onReachBottom: function () {
    let that = this;
    that.setData({
      loadmoreShow: true,
      page: that.data.page + 1
    });
    if (that.data.keyword) {
      that.getShopGoodsSearch();
    } else {
      that.getShopClassifyGoodsList();
    }
  },

  onShareAppMessage: function (res) {},
}

shop(options)
common(options)
Page(options)